//
//  UIColor+hexString.swift
//  EasyTrademarkRegqurySearch
//
//  Created by 伊伊 on 2024/2/28.
//

import Foundation
import UIKit

extension UIColor{
    convenience  init(hexString:String) {
       
        let string = hexString.trimmingCharacters(in: CharacterSet(charactersIn: "#"))
        self.init(hexString: string,alpha: 1)
    
    }
    convenience init(_ r: CGFloat, _ g: CGFloat, _ b: CGFloat, _ alpha: CGFloat){
        self.init(red: r/255.0, green: g/255.0, blue: b/255.0, alpha: alpha)
    }
    
    convenience  init(hexString:String,alpha:CGFloat) {
        let scanner = Scanner(string: hexString)
        var rgbValue: UInt64 = 0
        scanner.scanHexInt64(&rgbValue)
        let r = (rgbValue & 0xff0000) >> 16
        let g = (rgbValue & 0xff00) >> 8
        let b = rgbValue & 0xff
        self.init(
            red: CGFloat(r) / 0xff,
            green: CGFloat(g) / 0xff,
            blue: CGFloat(b) / 0xff, alpha: alpha)
    }
}

